package com.liangzhong.modules.leagueMatch.command
{
	import com.liangzhong.constants.ApplicationConstants;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.proxy.leagueMatch.LeagueMatchProxy;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**
	 *联赛 
	 * @author lake
	 * 
	 */	
	public class LeagueMatchCommand extends SimpleCommand
	{
		public function LeagueMatchCommand()
		{
			super();
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MATCH_PRE_SUCCESS,matchSuccessHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MATCH_BASE_SUCCESS,matchSuccessHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MATCH_CHAMPION_TRUN_SUCCESS,matchSuccessHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MATCH_CHAMPION_SUCCESS,matchSuccessHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MATCH_LEGEND_SUCCESS,matchSuccessHandler);
		}
		/**
		 * 比赛成功 
		 * @param e
		 * 
		 */		
		private function matchSuccessHandler(e :NotifierEvent):void
		{
			switch(e.type)
			{
				case NotifierEvent.MATCH_PRE_SUCCESS://预选赛
				{
					this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_BASE_INFO);
					this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_RELATION);
					break;
				}
				case NotifierEvent.MATCH_BASE_SUCCESS://甲级联赛
				{
					if(e.params.retcode == 0)
					{
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_CHAMPION_INFO);
					}
					else
					{
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_BASE_INFO);
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_RELATION);
					}
					break;
				}
				case NotifierEvent.MATCH_CHAMPION_TRUN_SUCCESS://冠军赛本轮通过
				{
					if(e.params.retcode == 0)
					{
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_CHAMPION_INFO);
					}
					else
					{
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_BASE_INFO);
						this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_RELATION);
					}
					break;
				}
				case NotifierEvent.MATCH_CHAMPION_SUCCESS://冠军赛
				{
					AppData.getInstance().leagueMatchManager.passStatus = 3;
					break;
				}
				case NotifierEvent.MATCH_LEGEND_SUCCESS://传奇
				{
					this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_BASE_INFO);
					this.sendNotification(ApplicationConstants.LEAGUEMATCH_GET_RELATION);
					break;
				}
			}
		}
		/**
		 *处理信息 
		 * @param notification
		 * 
		 */		
		override public function execute(notification :INotification):void
		{
			var proxy:LeagueMatchProxy = facade.retrieveProxy(LeagueMatchProxy.ProxyName) as LeagueMatchProxy;
			switch(notification.getName())
			{
				case ApplicationConstants.LEAGUEMATCH_GET_INFO://获取联赛信息
				{
					proxy.getLeagueInfo(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_GET_PRE_INFO://获取预选赛信息
				{
					proxy.getLeaguePreInfo(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_GET_BASE_INFO://获取基础联赛信息
				{
					proxy.getLeagueBaseInfo(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_GET_CHAMPION_INFO://获取冠军联赛信息
				{
					proxy.getLeagueChampionInfo(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_PRE_START://预选赛开始
				{
					proxy.preMatchStart(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_BASE_START://甲级联赛开始
				{
					proxy.baseMatchStart(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_CHAMPION_START://冠军联赛开始
				{
					proxy.championMatchStart(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_LEGEND_START://传奇赛开始
				{
					proxy.legendMatchStart(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_SIGN_STAR://签约球星
				{
					proxy.signStar(notification.getBody());
					break;
				}
				case ApplicationConstants.LEAGUEMATCH_GET_RELATION://获取签约关系
				{
					proxy.getClubrelation(notification.getBody());
					break;
				}
			}
		}
	}
}